(ns pro.fx-clj.hello-earth-rise.ui.hello-earth-rise
  (:require [fx-clj.core :as fx])
  (:import (javafx.scene.text Font FontWeight)
           (javafx.scene.paint Color)
           (javafx.animation Interpolator Timeline)
           (javafx.scene.image Image)))

(def ^:private message
  (str "Earthrise at Christmas: "
       "[Forty] years ago this Christmas, a turbulent world "
       "looked to the heavens for a unique view of our home "
       "planet. This photo of Earthrise over the lunar horizon "
       "was taken by the Apollo 8 crew in December 1968, showing "
       "Earth for the first time as it appears from deep space. "
       "Astronauts Frank Borman, Jim Lovell and William Anders "
       "had become the first humans to leave Earth orbit, "
       "entering lunar orbit on Christmas Eve. In a historic live "
       "broadcast that night, the crew took turns reading from "
       "the Book of Genesis, closing with a holiday wish from "
       "Commander Borman: \"We close with good night, good luck, "
       "a Merry Christmas, and God bless all of you -- all of "
       "you on the good Earth.\""))

(defn create-view []
  (let [text (fx/text {:layout-y       100
                       :text-origin    :top
                       :text-alignment :justify
                       :wrapping-width 400
                       :fill           (Color/rgb 187 195 107)
                       :font           (Font/font "SansSerif" FontWeight/BOLD 24.0)}
                      message)
        tt (fx/translate-transition {:node         text
                                     :duration     (fx/duration 75000 ms)
                                     :to-y         -820
                                     :interpolator Interpolator/LINEAR
                                     :cycle-count  Timeline/INDEFINITE})
        iv (fx/image-view (Image. "http://projavafx.com/images/earthrise.jpg"))
        scroll (fx/scroll-pane {:layout-x    50
                                :layout-y    180
                                :pref-width  400
                                :pref-height 85
                                :hbar-policy :never
                                :vbar-policy :never
                                :pannable    true}
                               text)
        root (fx/group iv scroll)]
    {:root     root
     :on-shown (fn [_] (.play tt))}))

(fx/sandbox #'create-view)